package com.example.feignserviceb.service;

import com.example.feignserviceb.config.DataConfigProperties;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

@FeignClient(name = "a-service-center",
        fallbackFactory = AServiceCenterFeignApiFallbackFactory.class)
public interface AServiceCenterFeignApi {

     /**
      * 声明式接口,远程调用http://product‐center/getAServiceInfo/{productNo}
      * @return
      */
     @RequestMapping("/getDataConfigProperties")
     public DataConfigProperties getAServiceInfo();
}

@Component
class  AServiceCenterFeignApiFallbackFactory implements FallbackFactory<AServiceCenterFeignApi> {

    @Override
    public AServiceCenterFeignApi create(Throwable throwable) {
        return new AServiceCenterFeignApi() {
            @Override
            public DataConfigProperties getAServiceInfo() {
                System.err.println("服务异常不可用") ;
                 return null;
            }
        };
    }
}